<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/9/13
 * Time: 13:04
 */

namespace App\CronTask;


use App\Enums\UrlEnums;
use App\Library\Auth;
use EasySwoole\EasySwoole\Crontab\AbstractCronTask;
use EasySwoole\HttpClient\HttpClient;

class LolpyleaStatsCron extends AbstractCronTask
{
    public static function getRule(): string
    {
        // TODO: Implement getRule() method.
        return '@daily';
    }
    public static function getTaskName(): string
    {
        // TODO: Implement getTaskName() method.
        // 定时任务名称
        return 'lolpyleaStats';
    }
    static function run(\swoole_server $server, int $taskId, int $fromWorkerId, $flags = null)
    {
        $url = UrlEnums::FJURL.UrlEnums::LOL_PYLEA_STATS_PATH.'?version=2&offset=0&limit=1000';
        $client = new HttpClient($url);
        list($s1, $s2) = explode(' ', microtime());
        $microtime = (float)sprintf('%.0f', (floatval($s1) + floatval($s2)) * 1000); //毫秒时间戳
        $option = [
            'path'      => UrlEnums::LOL_PYLEA_STATS_PATH,
            'api_time'  => $microtime
        ];
        $header = Auth::getInstance()->header($option);
        $client->setHeaders($header,true,false);
        $response = $client->get();
        $data = $response->getBody();
        $data = json_decode($data,true);
    }
}